# -*- coding: utf-8 -*-
# @Time : 2022/3/24 17:01

from src.Bugs.Database.bug_comment_database import BugCommentData, BugCommentDataSchema
from Common.yaml_method import YamlMethod


class BugComment:
    """
    获取缺陷评论接口
    """

    @staticmethod
    def bug_comment(bug_id):
        """
        获取缺陷评论接口
        :param bug_id: 缺陷ID
        :return:
        """

        code = YamlMethod().read_data('code.yaml')['code']

        comment_list = BugCommentData.query.filter_by(bug_id=bug_id).order_by(BugCommentData.create_time.desc()).all()

        comment_dict_list = []
        for c in comment_list:
            comment_dict = {'bug_id': c.bug_id, 'comment': c.comment,
                            'create_time': c.create_time.strftime("%Y-%m-%d, %H:%M:%S"), 'create_user': c.create_user}
            comment_dict_list.append(comment_dict)

        res = {
            'code': code[0],
            'message': 'success',
            'data': comment_dict_list
        }

        return res
